<?php 
/*
 module:		举报管理
 create_time:	2022-05-20 10:42:52
 author:	陕西格创
 contact:		
*/

namespace app\api\controller;

use app\api\service\ZhReportService;
use app\api\model\ZhReport as ZhReportModel;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;
use app\api\model\SysSite as SysSiteModel;
use app\api\model\Member as MemberModel;

class ZhReport extends Common {


	/**
	* @api {get} /ZhReport/index 01、首页数据列表
	* @apiGroup ZhReport
	* @apiVersion 1.0.0
	* @apiDescription  首页数据列表
	* @apiParam (输入参数：) {int}     		[limit] 每页数据条数（默认20）
	* @apiParam (输入参数：) {int}     		[page] 当前页码
	* @apiParam (输入参数：) {int}			[status] 状态 已处理|1|success,待审核|0|warning

	* @apiParam (失败返回参数：) {object}     	array 返回结果集
	* @apiParam (失败返回参数：) {string}     	array.status 返回错误码 201
	* @apiParam (失败返回参数：) {string}     	array.msg 返回错误消息
	* @apiParam (成功返回参数：) {string}     	array 返回结果集
	* @apiParam (成功返回参数：) {string}     	array.status 返回错误码 200
	* @apiParam (成功返回参数：) {string}     	array.data 返回数据
	* @apiParam (成功返回参数：) {string}     	array.data.list 返回数据列表
	* @apiParam (成功返回参数：) {string}     	array.data.count 返回数据总数
	* @apiSuccessExample {json} 01 成功示例
	* {"status":"200","data":""}
	* @apiErrorExample {json} 02 失败示例
	* {"status":" 201","msg":"查询失败"}
	*/
	function index(){
		$limit  = $this->request->get('limit', 20, 'intval');
		$page   = $this->request->get('page', 1, 'intval');

		$where = [];
		$where['status'] = $this->request->get('status', '', 'serach_in');

		$field = '*';
		$orderby = 'id desc';

		$res = ZhReportService::indexList(formatWhere($where),$field,$orderby,$limit,$page);
		return $this->ajaxReturn($this->successCode,'返回成功',htmlOutList($res));
	}

	/**
	* @api {post} /ZhReport/add 02、添加
	* @apiGroup ZhReport
	* @apiVersion 1.0.0
	* @apiDescription  添加
	* @apiParam (输入参数：) {string}			wxapp_id 平台id 
	* @apiParam (输入参数：) {int}				u_id 用户id 
	* @apiParam (输入参数：) {int}				r_id 被举报用户 
	* @apiParam (输入参数：) {string}			content 举报说明 
	* @apiParam (输入参数：) {string}			image 图片 
	* @apiParam (输入参数：) {int}				status 状态 已处理|1|success,待审核|0|warning

	* @apiParam (失败返回参数：) {object}     	array 返回结果集
	* @apiParam (失败返回参数：) {string}     	array.status 返回错误码  201
	* @apiParam (失败返回参数：) {string}     	array.msg 返回错误消息
	* @apiParam (成功返回参数：) {string}     	array 返回结果集
	* @apiParam (成功返回参数：) {string}     	array.status 返回错误码 200
	* @apiParam (成功返回参数：) {string}     	array.msg 返回成功消息
	* @apiSuccessExample {json} 01 成功示例
	* {"status":"200","data":"操作成功"}
	* @apiErrorExample {json} 02 失败示例
	* {"status":" 201","msg":"操作失败"}
	*/
	function add(){
        $wxapp_id = $this->request->post('wxapp_id');
        $uId      = $this->request->uid;
        if(!$wxapp_id){
            return $this->ajaxReturn($this->errorCode,'缺少平台参数');
        }
        $wxSetting = SysSiteModel::where('wxapp_id',$wxapp_id)->find();
        if(!$wxSetting){
            return $this->ajaxReturn($this->errorCode,'平台参数未配置');
        }
        
        $user = MemberModel::where(['uid' => $uId, 'wxapp_id' => $wxapp_id])->find();
        if(!$user){
            return $this->ajaxReturn($this->errorCode,'未知用户');
        }
		$postField = 'wxapp_id,u_id,r_id,content,image,status,createtime';
		$data = $this->request->only(explode(',',$postField),'post',null);
		$data['u_id'] = $uId;
		$res = ZhReportService::add($data);
		return $this->ajaxReturn($this->successCode,'操作成功',$res);
	}



}

